package com.smartao.core.service;

import java.io.Serializable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;

import com.smartao.core.dao.BaseDao;
import com.smartao.core.orm.entity.BaseEntity;

/**
 * Service父类， 使用@Transactional注解控制事务<br>
 * @param <T> 实体类型
 * @param <ID> 主键类型
 * @author Ricky
 */
public abstract class BaseEntityService<T extends BaseEntity<T>, ID extends Serializable> {
	
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	abstract protected  BaseDao<T, ID> getDao();
	
	public T findOne(ID id){
		Assert.notNull(id);
		return getDao().findOne(id);
	}
	
	public void save(T entity) {
		Assert.notNull(entity);
		getDao().save(entity);
	}

	public void delete(T entity) {
		Assert.notNull(entity);
		getDao().delete(entity);
	}

	public void delete(ID id) {
		Assert.notNull(id);
		getDao().delete(id);
	}
}
